module TR  #移动旋转模块

    def TR.TE(entArr,elv,ent)
        entArr.transform_entities(Geom::Transformation.new(elv), ent)
    end


    def TR.RT(entArr,org,axis,ang,ent)
        entArr.transform_entities(Geom::Transformation.rotation(org,axis,ang),ent)
    end

end

class WFS   #木模体系类

    include TR

    def initialize()   #构造函数



    end

    def rectPillarWFWK(b,h,l,groupW)

        group = groupW.entities.add_group  #默认群组
        entities = group.entities          #实例数组

        wf = rectPillarWF(b,h,l,group)

        wk = woodenKeel(0.05,0.1,l,group)
        wk.material = "Bisque"
        TR.TE(entities,[0,-110.mm,0],wk)

        b_wk_num = (b/0.2).to_i + 1
        b_wk_space = (b.mm*1000 - 50.mm)/b_wk_num
        
        for i in 0..b_wk_num - 1
            wk = wk.copy
            wk.material = "Bisque"
            TR.TE(entities,[b_wk_space,0,0],wk)
        end

    end

    def rectPillarWF(b,h,l,groupW)

        group = groupW.entities.add_group  #默认群组
        entities = group.entities          #实例数组

        bWF = woodenForm(b.mm*1000 + 20.mm,l.mm*1000,group)
        bWF.material = "Chocolate"
        TR.TE(entities,[-10.mm,0,0],bWF)
        TR.RT(entities,[0,0,0],X_AXIS,90.degrees,bWF)

        bWF = bWF.copy
        bWF.material = "Chocolate"
        TR.TE(entities,[0,h.mm*1000 + 10.mm,0],bWF)

        hWF = woodenForm(h.mm*1000,l.mm*1000,group)
        hWF.material = "Chocolate"
        TR.RT(entities,[0,0,0],X_AXIS,90.degrees,hWF)
        TR.RT(entities,[0,0,0],Z_AXIS,90.degrees,hWF)
        TR.TE(entities,[-10.mm,0,0],hWF)

        hWF = hWF.copy
        hWF.material = "Chocolate"
        TR.TE(entities,[b.mm*1000 + 10.mm,0,0],hWF)

        return group

    end
    
    
    def woodenForm(mod_x,mod_y,groupW)

        group = groupW.entities.add_group  #默认群组
        entities = group.entities          #实例数组

        points = [
            Geom::Point3d.new(0, 0, 0),
            Geom::Point3d.new(mod_x, 0, 0),
            Geom::Point3d.new(mod_x, mod_y, 0),
            Geom::Point3d.new(0, mod_y, 0),
            Geom::Point3d.new(0, 0, 0)
        ]

        face = entities.add_face(points)   
        status = face.pushpull(-10.mm, true)

        return group

    end

    def woodenKeel(b,h,l,groupW)

        group = groupW.entities.add_group  #默认群组
        entities = group.entities          #实例数组

        points = [
            Geom::Point3d.new(0, 0, 0),
            Geom::Point3d.new(b.m, 0, 0),
            Geom::Point3d.new(b.m, h.m, 0),
            Geom::Point3d.new(0, h.m, 0),
            Geom::Point3d.new(0, 0, 0)
        ]

        face = entities.add_face(points)   
        status = face.pushpull(-l.m, true)

        return group

    end

end




#####################
##矩形柱模+竖木楞测试
###################
WFS.new().rectPillarWFWK(1.2,1.4,5,Sketchup.active_model.active_entities.add_group)



###########
##矩形柱模测试
###########


WFS.new().rectPillarWF(1.2,1.4,5,Sketchup.active_model.active_entities.add_group)



###########
##木楞测试
###########
WFS.new().woodenKeel(0.05,0.1,4,Sketchup.active_model.active_entities.add_group)

###########
##木模测试
###########
WFS.new().woodenForm(600.mm,600.mm,Sketchup.active_model.active_entities.add_group)





